<div id="container">
	<div class="shell">		
		
		<!-- Main -->
		<div id="main">
			<div class="cl">&nbsp;</div>
			
			<!-- Content -->
			<div id="content">
				
				<!-- Box -->
				<div class="box">
					<!-- Box Head -->
					<div class="box-head">
						<h2 class="left">Sản phẩm</h2>
						<!--
						<div class="right">
							<label>Tìm kiếm</label>
							<input type="text" class="field small-field" />
							<input type="submit" class="button" value="Tìm" />
						</div>
						-->
					</div>
					<!-- End Box Head -->	

					<!-- Table -->
					<div class="table">
						<table width="100%" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<th width="13">#</th>
								<th>Tiêu đề</th>
								<th>Danh mục</th>  
								<th>Ẩn/hiện</th>
								<th width="110" class="ac">Chức năng</th>
							</tr>
							
							
							
							<?php
							$basepaging = '';
							$where='';
							if(isset($_GET['loaisp']) && $_GET['loaisp']!=0){
								$basepaging .= "&loaisp=".$_GET['loaisp'];
								$where .= ' AND sp.loai='.$_GET['loaisp'];
							}
							
							if(isset($_GET['danhmucsp'])  && $_GET['danhmucsp']!=0){
								$basepaging .= "&danhmucsp=".$_GET['danhmucsp'];
								$where .= ' AND sp.danhmuc='.$_GET['danhmucsp'];
							}
						
							
							$number=10;
							if(isset($_GET['start'])){
								$start=$_GET['start'];
							}else{
								$start=0;
							}
							
												
							// if($ordering){
								// $ordering= "ORDER BY $ordering";
							// }else{
								// $ordering='ORDER BY id DESC';
							// }
							$sqlnum="select sp.id from dm_sanpham AS sp, dm_sanpham_danhmuc AS dmsp WHERE sp.danhmuc=dmsp.id $where ";
						 	$sql="select sp.*, dmsp.title AS tendanhmuc from dm_sanpham AS sp, dm_sanpham_danhmuc AS dmsp WHERE sp.danhmuc=dmsp.id  $where ORDER BY sp.id DESC LIMIT $start, $number";
							$querynum=mysql_query($sqlnum);
							$totalnumber= mysql_num_rows($querynum);
							$query=mysql_query($sql);	
							
							// $value=array();
							// $value['query']=$query;
							// $value['number']=$number;
							// echo "<pre>";
							// print_r($query);
							// echo "</pre>";
							
							$i=0;
							while($mn=mysql_fetch_array($query))
							{
								if($i % 2==0)
								{
									$trclass="odd";
								}else{
									$trclass="";
								}
								$i++;
							?>
							<tr class="<?php echo $trclass?>">
								<td><?php echo $i;?></td>
								<td><h3><a href="?action=sanpham_sua&id=<?php echo $mn['id']?>"><?php echo $mn['tensp']?></a></h3></td>
								<td><?php echo $mn['tendanhmuc'];?></td>
								<td>
									<?php if($mn['publish']==1)
									{
										echo "<img src='images/bat.png'/>";
									}else{
										echo "<img src='images/tat.png'/>";
									}
									?>
									
								</td>								
								<td><a onclick="return confirm('Bạn có chắc chắn muốn xóa không !!! ');" href="?action=sanpham_xoa&id=<?php echo $mn['id']?>" class="ico del">Xóa</a><a href="?action=sanpham_sua&id=<?php echo $mn['id']?>" class="ico edit">Sửa</a></td>
							</tr>
							<?php
								
								//echo  $mn['title'];
							}
							?>						
							
						</table>
						<div class="pagging">
							<div class="left">Tổng: <?php echo $totalnumber?></div>
							<div class="right">
							<?php
							
							$base_url ='?action=sanpham'.$basepaging.'&';
							$pagintion = HamhaydungLibs::pagenav($base_url, $start, $totalnumber, $number);
							echo $pagintion;
							?>					

							</div>
						</div>
						<!-- End Pagging -->
						
					</div>
					<!-- Table -->
					
				</div>
				<!-- End Box -->
						

			</div>
			<!-- End Content -->
			
			<!-- Sidebar -->
			<div id="sidebar">
				
				<!-- Box -->
				<div class="box">
					
					<!-- Box Head -->
					<div class="box-head">
						<h2>Quản Lý</h2>
					</div>
					<!-- End Box Head-->
					
					<div class="box-content">
						<a href="?action=sanpham_sua&id=0" class="add-button"><span>Thêm loại sản phẩm</span></a>
						<div class="cl">&nbsp;</div>				
						<!-- Sort -->
						<div class="sort">
							<label>Lọc sản phẩm theo:</label>
							<form action="<?php echo BASE_URL ?>admin/index.php" method="GET" name="frmloc"/> 
							<input type="hidden" value="sanpham" name="action" />							
							<select name="loaisp" name="loaisp" class="field" onchange="getDanhmucByLoai(this.value)">
								<option value="0">Tất cả loại</option>
							
								<?php
								$sqlsec="select id, title from dm_sanpham_loai where state=1 ORDER BY title";								
								$querysec=mysql_query($sqlsec);	
								while($rowsec=mysql_fetch_array($querysec))
								{	
									echo "<option value='$rowsec[id]'>$rowsec[title]</option>";
								}			
								?>
							</select>
							
							<select name="danhmucsp" class="field" id="danhmucsp">
								<option value="0">Tất cả danh mục</option>
							</select>
							
							<input  class="fillter" type="submit" value="Lọc"/>
						</div>
						<!-- End Sort -->
					</div>
				</div>
				<!-- End Box -->
			</div>
			<!-- End Sidebar -->
			
			<div class="cl">&nbsp;</div>			
		</div>
		<!-- Main -->
	</div>
</div>